var majorityElement = function (nums) {
  let n = nums.length
  let map = {}
  let left = 0
  let right = n-1
  while (left <= right) {
    if (left != right) {
      if (map[nums[left]]) {
        map[nums[left]]++
      } else {
        map[nums[left]] = 1
      }
      if (map[nums[right]]) {
        map[nums[right]]++
      } else {
        map[nums[right]] = 1
      }
    } else {
      if (map[nums[left]]) {
        map[nums[left]]++
      } else {
        map[nums[left]] = 1
      }
    }
    left++
    right--
  }
  let stack = []
  for(var i in map) {
    if(map[i] > Math.floor(n/3)){
      stack.push(i)
    }
  }
  return stack
};
console.log(majorityElement([3,2,3]));